﻿#include "FITKDataCase.h"
#include "FITKAbaqusPart.h"
#include "FITK_Kernel/FITKCore/FITKAbstractObject.hpp"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractMaterial.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractSection.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKSectionAssignGroup.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractFields.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaBoundaryConditionManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaLoadManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAssembly.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaStepManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAmplitudeManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaProfileManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaFieldOutputManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaHistoryOutputManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaTimePointsManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConstraintManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionPropertyManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorSectionManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaPredefinedFieldManager.h"

//命名空间
namespace AbaqusData
{
    FITKDataCase::FITKDataCase()
    {
        //ID自增
        static int CASEIDMAX = 0;
        const QString caseName = QString("Model_%1").arg(++CASEIDMAX);
        this->setDataObjectName(caseName);

        const int id = this->getDataObjectID();
        //部件管理器
        _partManager = new FITKAbaqusPartManager;
        _partManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole, _partManager->FITKObj2QVarient());
        //模型装配
        _assembly = new Interface::FITKAbaAssembly;
        _assembly->setParentDataID(id);
        _assembly->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 1, _assembly->FITKObj2QVarient());
        //材料管理器
        _materialManager = new Interface::FITKMaterialManager;
        _materialManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 2, _materialManager->FITKObj2QVarient());
        //截面管理器
        _sectionManager = new Interface::FITKAbstractSectionManager;
        _sectionManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 3, _sectionManager->FITKObj2QVarient());
        
        //分析步管理器
        _stepManager = new Interface::FITKAbaStepManager;
        _stepManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 4, _stepManager->FITKObj2QVarient());
        //荷载管理器
        _loadManager = new Interface::FITKAbaLoadManager;
        _loadManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 5, _loadManager->FITKObj2QVarient());
        //边界条件管理器
        _bcManager = new Interface::FITKAbaBoundaryConditionManager;
        _bcManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 6, _bcManager->FITKObj2QVarient());
        //幅值管理器
        _ampManager = new Interface::FITKAbaAmplitudeManager;
        _ampManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 7, _ampManager->FITKObj2QVarient());
        //梁截面管理器
        _profileManager = new Interface::FITKAbaProfileManager;
        _profileManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 8, _profileManager->FITKObj2QVarient());
        //相互作用管理器
        _interactionManager = new Interface::FITKAbaInteractionManager;
        _interactionManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 9, _interactionManager->FITKObj2QVarient());

        //场输出管理器
        _fieldOutputManager = new Interface::FITKAbaFieldOutputManager;
        _fieldOutputManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 10, _fieldOutputManager->FITKObj2QVarient());

        //时间点管理器
        _timepointsManager = new Interface::FITKAbaTimePointsManager;
        _timepointsManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 11, _timepointsManager->FITKObj2QVarient());

        //约束管理器
        _contrainsManager = new Interface::FITKAbaConstraintManager;
        _contrainsManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 12, _contrainsManager->FITKObj2QVarient());
        //历程输出管理器
        _historyOutputManager = new Interface::FITKAbaHistoryOutputManager;
        _historyOutputManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 13, _historyOutputManager->FITKObj2QVarient());
        //相互作用属性管理器
        _interactionPropertyManager = new Interface::FITKAbaInteractionPropertyManager;
        _interactionPropertyManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 14, _interactionPropertyManager->FITKObj2QVarient());
        //连接器截面管理器
        _connectorSecManager = new Interface::FITKAbaConnectorSectionManager;
        _connectorSecManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 15, _connectorSecManager->FITKObj2QVarient());
        //预定义场管理器
        _predefineFieldManager = new Interface::FITKAbaPredefinedFieldManager;
        _predefineFieldManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 16, _predefineFieldManager->FITKObj2QVarient());
        //场管理器
        _fieldsManager = new Interface::FITKFieldsManager;
        _fieldsManager->setParentDataIDM(id);
        this->setUserData(Core::FITKUserRole + 17, _fieldsManager->FITKObj2QVarient());
        //截面指派组管理器
//         _sectionAssGroupManager = new Interface::FITKSectionAssignGroupManager;
//         _sectionAssGroupManager->setParentDataIDM(id);
//         this->setUserData(Core::FITKUserRole + 18, _sectionAssGroupManager->FITKObj2QVarient());
    }

    FITKDataCase::~FITKDataCase()
    {
        //释放内存
        if (_partManager != nullptr) delete _partManager;
        if (_assembly != nullptr) delete _assembly;
        if (_materialManager != nullptr) delete _materialManager;
        if (_sectionManager != nullptr) delete _sectionManager;
        if (_stepManager != nullptr) delete _stepManager;
        if (_loadManager != nullptr) delete _loadManager;
        if (_bcManager != nullptr) delete _bcManager;
        if (_ampManager != nullptr) delete _ampManager;
        if (_profileManager != nullptr) delete _profileManager;
        if (_interactionManager != nullptr) delete _interactionManager;
        if (_fieldOutputManager != nullptr) delete _fieldOutputManager;
        if (_timepointsManager != nullptr) delete _timepointsManager;
        if (_contrainsManager != nullptr) delete _contrainsManager;
        if (_historyOutputManager != nullptr) delete _historyOutputManager;
        if (_interactionPropertyManager != nullptr) delete _interactionPropertyManager;
        if (_connectorSecManager != nullptr) delete _connectorSecManager;
        if (_predefineFieldManager != nullptr) delete _predefineFieldManager;
        if (_fieldsManager != nullptr) delete _fieldsManager;
 //       if (_sectionAssGroupManager != nullptr) delete _sectionAssGroupManager;
    }
    void FITKDataCase::clear()
    {
        //释放内存
        if (_partManager != nullptr)  _partManager->clear();
        if (_assembly != nullptr)   _assembly->clear();
        if (_materialManager != nullptr)   _materialManager->clear();
        if (_sectionManager != nullptr)   _sectionManager->clear();
        if (_stepManager != nullptr)   _stepManager->clear();
        if (_loadManager != nullptr)   _loadManager->clear();
        if (_bcManager != nullptr)   _bcManager->clear();
        if (_ampManager != nullptr)   _ampManager->clear();
        if (_profileManager != nullptr)   _profileManager->clear();
        if (_interactionManager != nullptr)   _interactionManager->clear();
        if (_fieldOutputManager != nullptr)   _fieldOutputManager->clear();
        if (_timepointsManager != nullptr)   _timepointsManager->clear();
        if (_contrainsManager != nullptr)   _contrainsManager->clear();
        if (_historyOutputManager != nullptr)   _historyOutputManager->clear();
        if (_interactionPropertyManager != nullptr)   _interactionPropertyManager->clear();
        if (_connectorSecManager != nullptr)   _connectorSecManager->clear();
        if (_predefineFieldManager != nullptr)   _predefineFieldManager->clear();
        if (_fieldsManager != nullptr)   _fieldsManager->clear();
    }


//     CaseAnalysisType FITKDataCase::getAnsysType() const
//     {
//         //返回分析类型
//         return Explicit;
//     }

    FITKAbaqusPartManager* FITKDataCase::getPartManager()
    {
        //返回部件管理器
        return _partManager;
    }

    Interface::FITKMaterialManager * FITKDataCase::getMaterialManager()
    {
        //返回材料管理器
        return _materialManager;
    }

    Interface::FITKAbaProfileManager* FITKDataCase::getProfileManager()
    {
        //返回梁截面管理器
        return _profileManager;
    }

    Interface::FITKAbstractSectionManager* FITKDataCase::getSectionManager()
    {
        //返回截面管理器
        return _sectionManager;
    }

//     Interface::FITKSectionAssignGroupManager* FITKDataCase::getSectionAssignGroupManager()
//     {
//         return _sectionAssGroupManager;
//     }

    Interface::FITKAbaAssembly* FITKDataCase::getAssembly()
    {
        //返回模型装配
        return _assembly;
    }

    Interface::FITKAbaStepManager* FITKDataCase::getStepManager()
    {
        //返回分析步管理器
        return _stepManager;
    }

    Interface::FITKAbaLoadManager* FITKDataCase::getLoadManager()
    {
        //  返回荷载管理器
        return _loadManager;
    }

    Interface::FITKAbaBoundaryConditionManager* FITKDataCase::getBCManager()
    {
        //返回边界条件管理器
        return _bcManager;
    }

    Interface::FITKAbaConstraintManager* FITKDataCase::getConstraintManager()
    {
        //约束管理器
        return _contrainsManager;
    }

    Interface::FITKAbaInteractionPropertyManager* FITKDataCase::getInteractionPropertyManager()
    {
        //返回相互作用属性管理器
        return _interactionPropertyManager;
    }

    Interface::FITKAbaAmplitudeManager* FITKDataCase::getAmplitudeManager()
    {
        //返回幅值管理器
        return _ampManager;
    }

    Interface::FITKAbaFieldOutputManager* FITKDataCase::getFieldOutputManager()
    {
        return _fieldOutputManager;
    }
    Interface::FITKAbaTimePointsManager* FITKDataCase::getTimePointsManager()
    {
        //时间点管理器
        return _timepointsManager;

    }

    Interface::FITKAbaHistoryOutputManager* FITKDataCase::getHistoryOutputManager()
    {
        //历程输出管理器
        return _historyOutputManager;
    }

    Interface::FITKAbaInteractionManager* FITKDataCase::getInteractionManager()
    {
        //相互作用管理器
        return _interactionManager;
    }

    Interface::FITKAbaConnectorSectionManager* FITKDataCase::getConnectorSectionManager()
    {
        //连接器截面管理器
        return _connectorSecManager;
    }

    Interface::FITKAbaPredefinedFieldManager* FITKDataCase::getPredefinedFieldManager()
    {
        //预定义场管理器
        return _predefineFieldManager;
    }

    Interface::FITKFieldsManager* FITKDataCase::getFieldsManager()
    {
        return _fieldsManager;
    }



    void FITKDataCase::setAbsDataID(const int id)
    {
        Core::FITKAbstractNDataObject::setAbsDataID(id);
        //部件管理器 
        if(_partManager) _partManager->setParentDataIDM(id); 
        //模型装配 
        if(_assembly) _assembly->setParentDataIDM(id); 
        if(_assembly) _assembly->setParentDataID(id); 
        //材料管理器 
        if(_materialManager) _materialManager->setParentDataIDM(id); 
        //截面管理器 
        if(_sectionManager) _sectionManager->setParentDataIDM(id); 
        //分析步管理器 
        if(_stepManager) _stepManager->setParentDataIDM(id);
        //荷载管理器 
        if (_loadManager)_loadManager->setParentDataIDM(id);
        //边界条件管理器 
        if (_bcManager) _bcManager->setParentDataIDM(id);
        //幅值管理器 
        if (_ampManager) _ampManager->setParentDataIDM(id);
        //梁截面管理器 
        if (_profileManager) _profileManager->setParentDataIDM(id);
        //相互作用管理器 
        if (_interactionManager) _interactionManager->setParentDataIDM(id);
        //场输出管理器 
        if (_fieldOutputManager) _fieldOutputManager->setParentDataIDM(id);
        //时间点管理器 
        if (_timepointsManager) _timepointsManager->setParentDataIDM(id);
        //约束管理器 
        if (_contrainsManager)_contrainsManager->setParentDataIDM(id);
        //历程输出管理器 
        if (_historyOutputManager)_historyOutputManager->setParentDataIDM(id);
        //相互作用属性管理器 
        if (_interactionPropertyManager) _interactionPropertyManager->setParentDataIDM(id);
        //连接器截面管理器
        if (_connectorSecManager) _connectorSecManager->setParentDataIDM(id);
        //预定义场管理器
        if (_predefineFieldManager) _predefineFieldManager->setParentDataIDM(id);
        //场管理器
        if (_fieldsManager) _fieldsManager->setParentDataIDM(id);
    }

}